package com.shilm.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;


/**
 * Created by shilm on 16-6-6.
 */
public class PropertiesUtils {

    private static final Logger logger = LoggerFactory.getLogger(PropertiesUtils.class);

    public static Properties loadPro(String fileName) {
        Properties props = null;
        InputStream in = null;
        try {
            in = PropertiesUtils.class.getClassLoader().getResourceAsStream(fileName);
            if(in==null) {
                throw new FileNotFoundException(fileName + " file is not found");
            }
            props = new Properties();
            props.load(in);
        } catch(IOException e) {
            System.out.println(e);
        } finally {
            if(in!=null) {
                try {
                    in.close();
                } catch (IOException e) {
                    logger.error("close input stream failure,",e);
                }
            }
        }


        return props;
    }

    public static void main(String[] args) {
        logger.error("ssssss");
        Properties props = PropertiesUtils.loadPro("db.properties1");
        System.out.println(props.getProperty("jdbc.Driver"));
    }
}
